package com.acme.bankapp.service.event;

import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.service.email.Email;
import com.acme.bankapp.service.email.EmailService;

/**
 * @author Gregory Sobko
 */
public class EmailRegistrationListener  implements RegistrationListener{
    EmailService emailService;

    public EmailRegistrationListener(EmailService emailService) {
        this.emailService = emailService;
    }

    @Override
    public void onClientAdded(Client client) {
        Email email = new Email();
        email.setDestination(client.getName().replaceAll("\\s","_").toLowerCase() + "@bank.bank" );
        email.setTopic("You was registered!");
        emailService.enqueueEmail(email);
    }
}
